package com.example.Film.reviews.website.controllers;

import com.example.Film.reviews.website.dao.DirectorRepository;
import com.example.Film.reviews.website.dao.MovieRepository;
import com.example.Film.reviews.website.entities.Box_Office;
import com.example.Film.reviews.website.entities.Director;
import com.example.Film.reviews.website.entities.Movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.persistence.Access;
import java.util.List;

@Controller
@RequestMapping("directors")
public class DirectorController {

    @Autowired
    DirectorRepository directorRepository;

//    @Autowired
//    MovieRepository movieRepository;
    @GetMapping
    public String displayDirector(Model model){

        List<Director> directors = directorRepository.findAll();
        model.addAttribute("directors" ,directors);
//        List<Movie> movies = movieRepository.findAll();
//        model.addAttribute("allMovies",movies);
        return "director/list-director";
    }
    @GetMapping("/new")
    public String displayDirectorForm(Model model){

//        List<Movie> movies = movieRepository.findAll();
//        model.addAttribute("allMovies",movies);

        Director aDirector = new Director();
        model.addAttribute("director" ,aDirector);
        return "director/new-director";
    }
    @PostMapping("/save")
    public String createDirector(Model model, Director director){

       directorRepository.save(director);
        return "redirect:/directors";
    }

}
